Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

211
Vistas
DB | Postgres | How to check if IP is in a list of IPs or a range

I have a table that has a TEXT column that holds IP, IPs or range (for example 1.1.1.1/24). In case of multiple IPs, the IPs will be separated by a @##@ for example 1.1.1.1@##@2.2.2.2

The table with 4 rows:

    ip
    ------------------
    1.1.1.1
    1.1.1.1@##@2.2.2.2
    1.1.1.1/24
    3.3.3.3
    2.2.2.2

I want to get all the rows that contain the ip 1.1.1.1 or 3.3.3.3, meaning I want to get the first 4 rows. (1.1.1.1,1.1.1.1@##@2.2.2.2,1.1.1.1/24,3.3.3.3)

I found this solution in another stack-overflow question: select inet '192.168.1.5' << any (array['192.168.1/24', '10/8']::inet[]);

but I cannot understand how can I make it work for my specific table and to get me all the first 4 rows.

Please help Thanks in advance

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think this does what you want:

select t.*
from t
where '1.1.1.1'::inet <<= any(regexp_split_to_array(t.ips, '@##@')::inet[])

Here is a db<>fiddle.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda